<?php

class ServiceProviderController extends Zend_Controller_Action
{
	private $db;

    public function init()
    {
        // Hole den standardmäßigen DB Adapter (definiert in der Boootstrap.ini)
		$this->db = Zend_Db_Table::getDefaultAdapter();
    }

    public function indexAction()
    {
    	
    	   	
    	
   		$providers = new ServiceProviderModel();
   		$order = 'ServiceProvider_ID DESC';
   	
   		$this->view->providers = $providers->fetchAll(null, $order);
   		
   		
    }

    public function changeOfferAction()
    {
        // action body
    }

    public function changeProviderDataAction()
    {
        // action body
    }

    public function viewAction()
    {
    	//Hole Parameter ID
        $id = (string)$this->getRequest()->getParam('id');
        
        	
        
        /*
		 	SELECT *
			FROM ((ServiceProvider AS sp 
				INNER JOIN ServiceProvider_has_ServiceTypes AS sht ON sp.ServiceProvider_ID = sht.ServiceProvider_ID) 
				INNER JOIN ServiceTypes AS st ON st.ServiceTypes_ID = sht.ServiceTypes_ID
			WHERE sp.ServiceProvider_ID = $id;
		 */
//        
//        $select = new Zend_Db_Select($this->db);
//		$select->from(array('sp'=>'ServiceProvider'))
//				->join(array('sht'=>'ServiceProvider_has_ServiceTypes'), 'sp.ServiceProvider_ID = sht.ServiceProvider_ID')
//				->join(array('st'=>'ServiceTypes'), 'sht.ServiceTypes_ID = st.ServiceTypes_ID' )
//				->where('sp.ServiceProvider_ID =' .$id );
//	
//		$providerSet = $this->db->fetchAll($select);	
		
		//Array zur Übergabe aufbauen
		$providerData['ServiceProvider_ID']=$providerSet[0]['ServiceProvider_ID'];
		$providerData['ServiceProvider_name']=$providerSet[0]['ServiceProvider_name'];
		$providerData['ServiceProvider_info']=$providerSet[0]['ServiceProvider_info'];
		$providerData['ServiceProvider_services']=array();
		
		
		
		foreach ($providerSet as $p) {
			foreach ($p as $key => $value) {
				if($key=='serviceName')
				{
					$providerData['ServiceProvider_services'][]=$value;
				}
			}
		}
		
		//Daten an die View übergeben
		
		$this->view->providerData = $providerData;
		
		if ($mismatch != NULL) {
			$this->view->mismatch = $mismatch;
		}
		
		
		
		
    }
    
   
    public function deleteAction()
    {
        // action body
    }

    public function createAction()
    {
        // action body
    }


}











